package com.wfe.db;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import com.wfe.db.com.wfe.listener.WFEDeleteListener;
import com.wfe.db.com.wfe.listener.WFEInsertListener;
import com.wfe.db.com.wfe.listener.WFEUpdateListener;

public class HibernateUtil
{

	private static final SessionFactory sessionFactory;

	static
	{
		try
		{
			final Configuration config = new Configuration();
			config.setListener("save-update", new WFEUpdateListener());
			config.setListener("save", new WFEInsertListener());
			config.setListener("delete", new WFEDeleteListener());
			sessionFactory = config.configure("com/wfe/db/hibernate.cfg.xml").buildSessionFactory();

		}catch(final Throwable ex)
		{
			// Make sure you log the exception, as it might be swallowed
			System.err.println("Initial SessionFactory creation failed." + ex);
			throw new ExceptionInInitializerError(ex);
		}
	}

	public static SessionFactory getSessionFactory()
	{
		return sessionFactory;
	}

}
